package cn.wowjoy.pda.android_pharmacy.mvvm.vm.staticH;

import java.util.ArrayList;
import java.util.List;

import cn.wowjoy.pda.android_pharmacy.common.core.BaseViewModel;
import cn.wowjoy.pda.android_pharmacy.model.xmlEntity.putInfo.PutSingleBeen;

/**
 * Created by Administrator on 2017/8/16.
 */

public class StaticPutScanViewModel extends BaseViewModel {
    //每次被移除的一个Been
    public PutSingleBeen remove;
    public ArrayList<PutSingleBeen> FirstTotal;
    //第一次的全部数据 实体类   每取一次就把第一个移出去，放入到另外一个集合
    public ArrayList<PutSingleBeen> mMoveBaens;
//    public  ArrayList<PutSingleBeen> mTestBeen = new ArrayList<>();

    public boolean updateResult = false;

    public void show(ArrayList<PutSingleBeen> mDatas) {
        if (null == FirstTotal)
            FirstTotal = new ArrayList<>();
        FirstTotal.clear();
        FirstTotal.addAll(mDatas);

        if (null == mMoveBaens)
            mMoveBaens = new ArrayList<>();
        mMoveBaens.clear();
        mMoveBaens.addAll(mDatas);
    }

    //获取当前集合中即将移除的第一个
    public PutSingleBeen remove() {
        if (null != mMoveBaens && mMoveBaens.size() > 0) {
            remove = mMoveBaens.remove(0);
            return remove;
        }
        return null;
    }
    public ArrayList<PutSingleBeen> handPut(List<PutSingleBeen> mLists){
        ArrayList<PutSingleBeen> mHandCheckLists= new ArrayList<>();
        for(PutSingleBeen i : mLists){
            if(!i.isPut()){
                mHandCheckLists.add(i);
            }
        }
        return mHandCheckLists;
    }
    //计算当前集合中已经被检查的
    public int calcNum(){
        int num=0;
        for(PutSingleBeen inHospitalPatientBeen : FirstTotal ){
            if(inHospitalPatientBeen.isPut()){
                num++;
            }
        }
        return num;
    }

    /**
     * 方案一
     * 1.首先判断是否在集合中
     * 2.判断匹配的药的数量是否为0
     * 3.不为0就 -1  为 0但是还能扫到 说明有问题
     * 4.最终集合中的所有药的数量属性均为0 不然视为有问题
     * <p>
     * 方案二  只考虑种类  不考虑单个药品的数量
     * 1.首先判断是否在药品种类集合中
     * 2,匹配就把它从集合中移出去，不匹配就弹框提示
     * 3.最终集合数据为0
     */
    public PutSingleBeen checkExist(String stringExtra){
        if(null != mMoveBaens && mMoveBaens.size()>0){
            for (PutSingleBeen inHospitalPatientBeen : mMoveBaens){
                if(null != inHospitalPatientBeen.getYPSPBM() && inHospitalPatientBeen.getYPSPBM().equals(stringExtra)){
                    return inHospitalPatientBeen;
                }
                if( null != stringExtra && stringExtra.length()>= 7){
                    if(null != inHospitalPatientBeen.getYPJGBM() && inHospitalPatientBeen.getYPJGBM().equals(stringExtra.substring(0,7))){
                        return inHospitalPatientBeen;
                    }
                }

//                if(null != inHospitalPatientBeen.getKFWZMC() && inHospitalPatientBeen.getKFWZMC().length()>7 &&  inHospitalPatientBeen.getKFWZMC().substring(0,7).equals(stringExtra)){
//                    return inHospitalPatientBeen;
//                }
            }
        }
        return null;
    }

    public  boolean   checkSecond(PutSingleBeen inHospitalPatientBeen) {
        String ypspbm = inHospitalPatientBeen.getYPSPBM();
        if (null != mMoveBaens && mMoveBaens.size() > 0) {
            for (PutSingleBeen i : mMoveBaens) {
                if (null != i.getYPSPBM() && i.getYPSPBM().equals(inHospitalPatientBeen.getYPSPBM())
                        || null != i.getYPJGBM() && i.getYPJGBM().equals(inHospitalPatientBeen.getYPJGBM())
                        || null != i.getKFWZMC() && i.getKFWZMC().equals(inHospitalPatientBeen.getKFWZMC())
                        ) {
                    //匹配成功
                    if (i.isPut()) {
                        return false;
                    }
                    i.setPut(true);
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 药品全部取完后做检查
     * 是否当前药单的所有药的数量都为 0
     */

    public boolean checkTotal() {
        for (PutSingleBeen PutBeen : mMoveBaens) {
            if (!PutBeen.isPut()) {
                return false;
            }
        }
        return true;

    }
}
